package org.example.ch07.service;

import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * @ClassName ProduceService
 * @Description TODO
 * @Author Kx
 * @Date 2025/10/14 11:41
 * @Version 1.0
 */
@Service
@RequiredArgsConstructor
public class ProduceService {
    private final RabbitTemplate rabbitTemplate;

    public void send(String message) {
        // 创建消息的唯一ID
        CorrelationData correlationData = new CorrelationData();
        correlationData.setId(UUID.randomUUID().toString());
        // 投递消息
        rabbitTemplate.convertAndSend("test.exchange","key.test",message,correlationData);
    }
}
